<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理页面</title>
<link href="{webroot}theme/admin/css/iframe.css" rel="stylesheet" type="text/css" />
<link href="{webroot}theme/admin/css/iconfont.css" rel="stylesheet" type="text/css" />
<link href="{webroot}lib/css/jquery.colorpicker.css" rel="stylesheet" type="text/css" />
<link href="{webroot}lib/css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="{webroot}lib/js/jquery.js"></script>
<script src="{webroot}lib/js/jquery-migrate-1.1.0.min.js"></script>
<script src="{webroot}lib/js/base.js"></script>
<script src="{webroot}lib/tips/jquery.tips.js"></script>
<script src="{webroot}lib/validator/jquery.validator.js"></script>
<script src="{webroot}lib/validator/zh_CN.js"></script>
<script src="{webroot}lib/js/jquery.livequery.js"></script>
<script src="{webroot}lib/js/jquery.colorpicker.js"></script>
<script src="{webroot}lib/js/jquery.autocomplete.js"></script>
<script src="{webroot}theme/admin/js/admin.js"></script>
<script src="{webroot}lib/dialog/artdialog.js"></script>
<!--[if lt IE 9]>
<script src="{webroot}lib/js/html5.js"></script>
<![endif]-->
<script>
$().ready(function() {
	var $tableid = $("#voteitem");
	var $addInput = $("#addInput");
	$addInput.click( function() {
		var sonnum=$("#voteitem li").size();
		var textValueTrHtml = '<li><input type="text" name="t2" id="t2_'+sonnum+'" size="40" maxlength="50" data-rule="项目名称:required;" class="ip" /><input type="text" name="t3" id="t3_'+sonnum+'" size="10" maxlength="10" data-rule="初始票数:required;" value="0" class="ip" /> <a href="javascript:;" class="leftarr iconfont">&#xe60a;</a><a href="javascript:;" class="rightarr iconfont">&#xe608;</a><a href="javascript:;" class="delarr iconfont">&#xe602;</a></li>';
	   var sonnum=$("#voteitem li").size()
	   if(sonnum==10)
	   {
		   alert("最多只能添加10个");
		   return false;
	   }
	   else
	   {
		   $tableid.append(textValueTrHtml);
		 }
	})
	
	$(".leftarr").livequery("click", function() {
		var $ValueTr = $(this).parent();
		var $PrevTr = $ValueTr.prev("li");
		var PrevTrIndex = $("#voteitem li").index($PrevTr);
		$PrevTr.insertAfter($ValueTr);
	});
	
	$(".rightarr").livequery("click", function() {
		var $ValueTr = $(this).parent();
		var $NextTr = $ValueTr.next("li");
		if ($NextTr.length > 0) {
			$NextTr.insertBefore($ValueTr);
		}
	});
	
	$(".delarr").livequery("click", function() {
		if (confirm("\u60a8\u786e\u5b9a\u8981\u5220\u9664\u5417\uff1f") == true) {
		var sonnum=$("#voteitem li").size();
	   if(sonnum<=2)
	   {
		   alert("\u4e0d\u80fd\u5c11\u4e8e\u0032\u4e2a");
		   return false;
	   }
	   else
	   {
		  $(this).parent().remove();
		 }
 
		}
	});
 
 
});
</script>
</head>
<body>

<div class="layout-center">
	<div class="right_subject">当前位置：扩展 > <a href="?">投票管理</a> > <a href="?act=edit&id={id}&page={page}&nat={nat}">修改投票</a></div>
    <div class="right_body">
        <div class="table_form">
            <form class="formname" method="post">
                <div class="form_group">
                    <div class="form_txt">投票名称：</div>
                    <div class="form_input"><input type="text" name="t0" size="30" maxlength="50" value="{datadb(0,0)}" class="ip" data-rule="投票名称:required;" /></div>
                </div>
                <div class="form_group">
                    <div class="form_txt">投票类型：</div>
                    <div class="form_input">
                    <input type="radio" name="t1" id="t1_1" value="1" {if 1=datadb(1,0)}checked="checked"{/if} /><label for="t1_1">单选</label>
                    <input type="radio" name="t1" id="t1_2" value="2" {if 2=datadb(1,0)}checked="checked"{/if} /><label for="t1_2">多选</label></div>
                </div>
                <div class="form_group">
                    <div class="form_txt">投票项目：</div>
                    <div class="form_input">
                    <input type="button" value="增加项目" class="bnt_save" id="addInput">
                       <ul class="voteitem" id="voteitem">
                       {dim itemarr:itemarr=split(datadb(2,0),",")}
                       {dim resultarr:resultarr=split(datadb(3,0),",")}
                       {for i=0 to ubound(itemarr)}
                       <li><input type="text" name="t2" id="t2_{i}" size="40" maxlength="50" value="{itemarr(i)}" data-rule="项目名称:required;" class="ip" /><input type="text" name="t3" id="t3_{i}" size="10" maxlength="10" value="{resultarr(i)}" data-rule="初始票数:required;" class="ip" /> <a href="javascript:;" class="leftarr iconfont">&#xe60a;</a><a href="javascript:;" class="rightarr iconfont">&#xe608;</a><a href="javascript:;" class="delarr iconfont">&#xe602;</a></li>
                       {/for}
                       </ul>
                    </div>
                </div>
                <div class="form_group">
                    <div class="form_txt">是否审核：</div>
                    <div class="form_input"><input type="checkbox" name="t4" id="t4" value="1" {if 1=datadb(4,0)}checked="checked"{/if} /><label for="t4">通过审核</label></div>
                </div>
                <div class="form_group">
                    <div class="form_bnt"><input type="submit" value="保存" class="bnt_save"><input type="button" value="返回" class="bnt_normal goback"></div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
$(".formname").validator(
	{
		stopOnError:true,
        theme:'yellow_top',
		ignore:':hidden',
		beforeSubmit:function(){$("input[type='submit']").attr("disabled",true);},
		valid:function(form)
		{
			if($("input[name=t2]").length<2)
			{
				$.fn.tips({content:"请至少添加两个投票项目"});
				$("input[type='submit']").attr("disabled",false);
				return false;
			}
			$.fn.tips({type:'loading',content:'数据提交中'});
			$.ajax(
			{
				url:"?act=editdb&id={id}",
				type:"post",
				data:$(form).serialize(),
				success:function(data){
					data=jQuery.parseJSON(data);
					var type="warn";
					if(data.status=="y"){type="ok";}
					$.fn.tips({type:type,content:data.info});
					if(data.status=="y"){setTimeout('location.href="?page={page}&nat={nat}"',1000);}
					else
					{$("input[type='submit']").attr("disabled",false);}
					
				}
			});
		},
		invalid:function(){$("input[type='submit']").attr("disabled",false);}
	}
);
</script>
</body>
</html>